package com.quad.innovators.salesease.controller;

import com.quad.innovators.salesease.annotation.Log;
import com.quad.innovators.salesease.common.result.Result;
import com.quad.innovators.salesease.constants.SystemConstants;
import com.quad.innovators.salesease.enums.LogModuleEnum;
import com.quad.innovators.salesease.model.dto.CaptchaResult;
import com.quad.innovators.salesease.model.dto.LoginResult;
import com.quad.innovators.salesease.model.query.LoginQuery;
import com.quad.innovators.salesease.service.AuthService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;


@Tag(name = "01.认证中心")
@RestController
@RequestMapping(SystemConstants.BACKEND_API + "/auth")
@RequiredArgsConstructor
@Slf4j
public class AuthController {

    private final AuthService authService;

    @Operation(summary = "登录")
    @PostMapping("/login")
    @Log(value = "登录", module = LogModuleEnum.LOGIN)
    public Result<LoginResult> login(@Valid @RequestBody LoginQuery loginQuery) {
        LoginResult loginResult = authService.login(loginQuery);
        return Result.success(loginResult);
    }

    @Operation(summary = "注销")
    @DeleteMapping("/logout")
    @Log(value = "注销", module = LogModuleEnum.LOGIN)
    public Result<?> logout() {
        authService.logout();
        return Result.success();
    }

    @Operation(summary = "获取验证码")
    @GetMapping("/captcha")
    @Log(value = "获取验证码", module = LogModuleEnum.LOGIN)
    public Result<CaptchaResult> getCaptcha() {
        CaptchaResult captcha = authService.getCaptcha();
        return Result.success(captcha);
    }

}
